package org.restly.doc;

import com.sun.javadoc.*;
import org.restly.core.ResourceInfo;
import org.restly.Resource;

import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;

/**
 * Nov 27, 2008, 4:12:58 AM
 *
 * @author <a href="mailto:erik.beeson@gmail.com">Erik Beeson</a>
 */
public class RestlyDoclet extends Doclet {
	public static boolean validOptions(String[][] options, DocErrorReporter docErrorReporter) {
		System.out.println("options = " + Arrays.deepToString(options));
		System.out.println("docErrorReporter = " + docErrorReporter);
		return true;
	}

	public static boolean start(RootDoc rootDoc) {
		List<ResourceDoc> resourceDocs = new ArrayList<ResourceDoc>();

		String outputDir = null;

		for(String[] options : rootDoc.options()) {
			if(options.length > 1 && "-d".equals(options[0])) {
				outputDir = options[1];
			}

			for(String option : options) {
				System.out.println("option = " + option);
			}
			System.out.println();
		}

		System.out.println("outputDir = " + outputDir);

		for(ClassDoc classDoc : rootDoc.classes()) {
			for(AnnotationDesc annotationDesc : classDoc.annotations()) {
				for(AnnotationDesc.ElementValuePair elementValuePair : annotationDesc.elementValues()) {
					if(Resource.class.getName().equals(elementValuePair.element().containingClass().toString()) &&
							"value".equals(elementValuePair.element().name())) {
						String path = (String) elementValuePair.value().value();
						System.out.println("Generating docs for resource: " + path);
						resourceDocs.add(new ResourceDoc(path, classDoc));
					}
				}
			}
		}
		return true;
	}
}
